this.BX=this.BX||{};(function(e,t,r,i,n,o){"use strict";var a=function(){function e(t){babelHelpers.classCallCheck(this,e);this.grid=BX.Main.gridManager.getInstanceById(t.gridId);this.initGrid()}babelHelpers.createClass(e,[{key:"getGridBodyRows",value:function e(){return this.grid.getRows().getBodyChild()}},{key:"initGrid",value:function e(){var t=this;r.EventEmitter.subscribe("Grid::updated",(function(e){var r=e.getCompatData()[0];if(r&&r.getId()===t.grid.getId()){var i=10;setTimeout(t.initGridRows.bind(t),i)}}));this.initGridRows()}},{key:"initGridRows",value:function e(){var t=this.getGridBodyRows();if(t.length===0){for(var r=0;r<5;r++){this.prependRowEditor()}}else{t.forEach((function(e){e.edit()}))}}},{key:"prependRowEditor",value:function e(){var t=this.grid.prependRowEditor();t.setId("");t.unselect()}},{key:"removeGridSelectedRows",value:function e(){var t=this.grid.getRows().getSelected(false);if(i.Type.isArray(t)){t.forEach((function(e){e.hide()}));this.grid.getRows().reset()}}}]);return e}();var s=function(){babelHelpers.createClass(e,null,[{key:"createApp",value:function t(r,i){var n=new e(r,i);n.app=o.BitrixVue.createApp(n.getAppConfig());n.app.mount(i.settingsFormSelector);return n}}]);function e(t,r){babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"newDirectoryValue","-1");this.gridController=t;this.directoryItems=i.Type.isArray(r.directoryItems)?r.directoryItems:[];this.selectedDirectory=this.newDirectoryValue;if(r.selectedDirectory){var n=this.directoryItems.find((function(e){return e.VALUE===r.selectedDirectory}));if(n){this.selectedDirectory=n.VALUE}}}babelHelpers.createClass(e,[{key:"reloadDirectory",value:function e(t){var r=new i.Uri(location.href);r.setQueryParam("directoryTableName",t);location.href=r.toString()}},{key:"getAppConfig",value:function e(){var t=this;return function(){return{data:function e(){return{directoryName:null,directoryValue:t.selectedDirectory,directoryItems:t.directoryItems}},computed:{selectedDirectoryName:function e(){if(this.isNewDirectory){return i.Loc.getMessage("IBLOCK_PROPERTY_TYPE_DIRECTORY_SETTINGS_NEW_DIRECTORY_NAME")}return this.directoryItemsMap[this.directoryValue]},directoryItemsMap:function e(){var t={};this.directoryItems.forEach((function(e){t[e.VALUE]=e.NAME}));return t},directoryItemsFull:function e(){var r=[{NAME:i.Loc.getMessage("IBLOCK_PROPERTY_TYPE_DIRECTORY_SETTINGS_NEW_DIRECTORY_NAME"),VALUE:t.newDirectoryValue}];r.push.apply(r,babelHelpers.toConsumableArray(this.directoryItems));return r},directoryItemsAsMenuItems:function e(){var t=this;return this.directoryItemsFull.map((function(e){return{id:e.VALUE,text:e.NAME,onclick:t.onSelectDirectoryItem.bind(t)}}))},isNewDirectory:function e(){return this.directoryValue===t.newDirectoryValue}},methods:{getDirectoryDropdownMenu:function e(t){var r="directory-items";var i=n.MenuManager.getMenuById(r);if(i&&t&&i.getPopupWindow().bindElement!==t){n.MenuManager.destroy(i.getId());i=null}if(!i&&t){i=n.MenuManager.create({id:r,items:this.directoryItemsAsMenuItems,bindElement:t})}return i},toggleDirectoryDropdown:function e(t){this.getDirectoryDropdownMenu(t.target).toggle()},onSelectDirectoryItem:function e(r,i){this.directoryValue=i.id;this.getDirectoryDropdownMenu().close();t.reloadDirectory(this.directoryValue)},normalizeName:function e(t){var r=t.target;if(r){r.value=BX.translit(r.value,{change_case:"L",replace_space:"",delete_repeat_replace:true})}},addNewRow:function e(){t.gridController.prependRowEditor()}}}}()}}]);return e}();var c=function(){function e(t){babelHelpers.classCallCheck(this,e);this.gridController=new a(t);this.signedParameters=t.signedParameters;this.settingsForm=s.createApp(this.gridController,t);this.initErrorAlert();this.initSaveButton()}babelHelpers.createClass(e,[{key:"removeGridSelectedRows",value:function e(){this.gridController.removeGridSelectedRows()}},{key:"initSaveButton",value:function e(){var t=this;var r=document.querySelector("#ui-button-panel-save");if(r){r.addEventListener("click",function(){var e=babelHelpers.asyncToGenerator(regeneratorRuntime.mark((function e(n){return regeneratorRuntime.wrap((function e(o){while(1){switch(o.prev=o.next){case 0:n.preventDefault();o.next=3;return t.clearErrors();case 3:i.ajax.runComponentAction("bitrix:iblock.property.type.directory.settings","save",{data:t.getFormData(),mode:"class",signedParameters:t.signedParameters}).then((function(e){r.classList.remove("ui-btn-wait");location.reload()}))["catch"]((function(e){r.classList.remove("ui-btn-wait");t.showErrors(e.errors)}));case 4:case"end":return o.stop()}}}),e)})));return function(t){return e.apply(this,arguments)}}())}}},{key:"clearErrors",value:function e(){var t=this;return new Promise((function(e,r){var i=300;t.errorAlert.hide();setTimeout(e,i)}))}},{key:"showErrors",value:function e(t){this.errorAlert.setText(t.map((function(e){return e.message})).join("<br>"));this.errorAlert.renderTo(document.querySelector("#ui-button-panel"))}},{key:"initErrorAlert",value:function e(){this.errorAlert=new t.Alert({color:t.AlertColor.DANGER,animated:true,customClass:"iblock-property-type-directory-settings-errors-container"})}},{key:"getFormData",value:function e(){var t=new FormData;t.append("fields[DIRECTORY_NAME]",this.settingsForm.app._instance.data.directoryName||"");t.append("fields[DIRECTORY_TABLE_NAME]",this.settingsForm.app._instance.data.directoryValue||"");var r=0;this.gridController.getGridBodyRows().forEach((function(e){var i=parseInt(e.getId());if(isNaN(i)||!i){r++;i="n"+r}var n=e.getEditorValue();if(e.isShown()===false){n.UF_DELETE="Y"}for(var o in n){if(Object.hasOwnProperty.call(n,o)){t.append("fields[DIRECTORY_ITEMS][".concat(i,"][").concat(o,"]"),n[o])}}}));return t}}]);return e}();e.PropertyDirectorySettings=c})(this.BX.Iblock=this.BX.Iblock||{},BX.UI,BX.Event,BX,BX.Main,BX.Vue3);
//# sourceMappingURL=script.map.js